package collections;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class IteratorTest {
    public static void main(String[] args) {
        List<String> list = new LinkedList<>();
        list.add("111");
        list.add("222");
        list.add("333");
        list.add("444");
        list.add("555");
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            String  key = iterator.next();
            if (key.equals("222")) {
                iterator.remove();
            }
            System.out.println(key);
        }
        System.out.println("----------------------");
        for (String key : list) {
            System.out.println(key);

        }
    }
}
